<script setup>
import { personAddServe } from '@/api/person'
import { ref } from 'vue'

const emit = defineEmits(['after'])
//录入
const dialogVisibleEnter = ref(false)
const n_name = ref('')
const n_stu_id = ref('')
const onOpenEnter = () => {
  n_name.value = ''
  n_stu_id.value = ''
  dialogVisibleEnter.value = true
}
const onEnter = async () => {
  await personAddServe({ name: n_name.value, stu_id: n_stu_id.value })
  ElMessage.success({ message: '录入成功', offset: 70 })
  dialogVisibleEnter.value = false
  emit('after')
}
const handleInput = (value) => {
  n_stu_id.value = value.replace(/\D/g, '')
}
defineExpose({
  onOpenEnter
})
</script>

<template>
  <el-dialog v-model="dialogVisibleEnter" title="录入维修人员" width="38%">
    <div style="height: 50px; margin-bottom: 15px; display: flex; justify-content: space-evenly">
      <el-form inline>
        <el-form-item style="width: 200px; margin-right: 5px">
          <div>姓名:</div>
          <el-input v-model="n_name" placeholder="请输入名字"></el-input>
        </el-form-item>
        <el-form-item style="width: 200px">
          <div>学号:</div>
          <el-input v-model="n_stu_id" placeholder="请输入学号" @input="handleInput"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisibleEnter = false">取消</el-button>
        <el-button type="primary" @click="onEnter" :disabled="!n_name || !n_stu_id">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="" scoped></style>
